package com.example.leetdemo.process;

import com.example.leetdemo.utils.DateUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

public class Solution373 {

    public List<List<Integer>> kSmallestPairs(int[] nums1, int[] nums2, int k) {
        List<List<Integer>> list = new ArrayList<>(k);
        PriorityQueue<int[]> priorityQueue = new PriorityQueue<>(
                (o1, o2) -> {
                    if (o1[0] > o2[0]) {
                        return 1;
                    } else if (o1[0] < o2[0]) {
                        return -1;
                    } else {
                        if (o1[1] >= o2[1]) {
                            return 1;
                        } else {
                            return -1;
                        }
                    }
                });

        int p = 0, q = 0;
        while ((p + 1) * (q + 1) <= k) {
            if (nums1[p + 1] + nums2[q] >= nums1[p] + nums2[q + 1]) {
                p++;
            } else {
                q++;
            }
            if (q == nums2.length) {
                p = k / q + 1;
                break;
            }
            if (p == nums1.length) {
                q = k / p + 1;
                break;
            }
        }

        for (int i = 0; i < Math.min(nums1.length, p); i++) {
            for (int j = 0; j < Math.min(nums2.length, q); j++) {
                int[] temp = new int[3];
                temp[0] = nums1[i] + nums2[j];
                temp[1] = nums1[i];
                temp[2] = nums2[j];
                priorityQueue.add(temp);
            }
        }
        for (int i = 0; i < k; i++) {
            int[] temp = priorityQueue.poll();
            List<Integer> re = new ArrayList<>();
            re.add(temp[1]);
            re.add(temp[2]);
            list.add(re);
        }
        return list;
    }

    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        long overflowSeconds = DateUtils.localDateTimeToMilli(now) / 1000 % 300;
        String endTime = DateUtils.format(now.minusSeconds(overflowSeconds));
        String beginTime = DateUtils.format(now.minusSeconds(overflowSeconds).minusSeconds(300));
        System.err.println(endTime);
        LocalDateTime dateTime1 = DateUtils.parse("2024-11-11 00:00:00");
        LocalDateTime dateTime2 = DateUtils.parse("2025-02-06 00:00:00");
        System.err.println(dateTime2.getDayOfYear()  + 366 - dateTime1.getDayOfYear());

        BigDecimal bigDecimal = new BigDecimal(3.5248);
        System.err.println(bigDecimal.longValue());

        System.err.println(beginTime.length());
        System.err.println(DateUtils.msToLocalDateTime(1733294040000L));
    }

}
